package com.fit.pages.homework;

import org.apache.tapestry5.annotations.InjectPage;
import org.apache.tapestry5.annotations.OnEvent;
import org.apache.tapestry5.annotations.Persist;
import org.apache.tapestry5.annotations.Property;
import org.apache.tapestry5.ioc.annotations.Inject;

import com.fit.annotations.AdminAccess;
import com.fit.annotations.AnonymousAccess;
import com.fit.annotations.ProfessorAccess;
import com.fit.annotations.StudentAccess;
import com.fit.dao.homework.HomeworkDAO;
import com.fit.dao.user.UserDAO;
import com.fit.entities.homework.Homework;
import com.fit.entities.language.Language;
import com.fit.entities.user.User;
import com.fit.model.MD5;
import com.fit.pages.ErrorPage;
import com.fit.pages.homework.Browse;
@AdminAccess
@AnonymousAccess
@ProfessorAccess
@StudentAccess
public class Add {

	@Property
	private Homework homework;
	@Inject
	private HomeworkDAO homeworkDAO;
	@InjectPage
	private ErrorPage errorPage;

	 @Persist
	 @Property
	 private String error;
	 
	 @Persist
	 @Property
	 private String confirmation;


	 void onPrepare() {
	  homework = new Homework();
	 }

	 Object onSubmitFromCreateForm() {
	  error="";
	  confirmation="";
	   
	   homeworkDAO.save(homework);
	   confirmation = "Language successfully added";
	   return Browse.class;
	  
	  
	  
	  
	 }
	 
	 @OnEvent(component = "ResetConfLink")
	 Object onResetConfLink() {
	  confirmation="";
	  return null;
	 }
	 
	 @OnEvent(component = "ResetErrorLink")
	 Object onResetErrorLink() {
	  error="";
	  return null;
	 }
	 
}
